(function ($) {
    $.VamtamSlider.createCaptionEffect = function (settings) {
        var customSettings = $.extend({
            runSettings: {},
            captionsCssOff: {
                opacity: 0,
                left: -300
            },
            captionsCssOn: {
                opacity: 1,
                left: 0
            },
            wrapperCssOff: {
                opacity: 0
            },
            wrapperCssOn: {
                opacity: 1
            }
        }, settings);
        return function (originalCfg) {
            var cfg = $.extend({}, originalCfg, customSettings.runSettings),
                oldWrapper = cfg.toHide.data("captionsWarapper"),
                newWrapper = cfg.toShow.data("captionsWarapper");
            $(oldWrapper).find(".caption").filter(function () {
                return (/^\s*$/).test(this.innerHTML);
            }).remove();
            $(newWrapper).find(".caption").filter(function () {
                return (/^\s*$/).test(this.innerHTML);
            }).remove();
            var toHide = $(oldWrapper).find(".caption"),
                toShow = $(newWrapper).find(".caption"),
                toHideLength = toHide.length,
                toShowLength = toShow.length,
                duration = "captionFxTime" in cfg ? cfg.captionFxTime : cfg.slider.options.captionFxTime || cfg.duration,
                delay = "captionFxDelay" in cfg ? cfg.captionFxDelay : cfg.slider.options.captionFxDelay || 0;
            if (!toHide.length && !toShow.length) {
                setTimeout(cfg.callback, duration + delay);
                return;
            }
            var easing = "captionFxEasing" in cfg ? cfg.captionFxEasing : cfg.slider.options.captionFxEasing || cfg.easing,
                queue = !! cfg.slider.options.captionQueue,
                sliderRoot = $(cfg.slider.element),
                halfTime = Math.ceil(duration / 2),
                quarterTime = Math.ceil(duration / 4);
            var hideDuration = isComplexSlideWrapper(cfg.toHide, cfg.slider) ? cfg.slider.options.complexSlidesDuration : duration;
            var showDuration = isComplexSlideWrapper(cfg.toShow, cfg.slider) ? cfg.slider.options.complexSlidesDuration : duration;
            var halfHideTime = Math.ceil(hideDuration / 2),
                quarterHideTime = Math.ceil(hideDuration / 4),
                halfShowTime = Math.ceil(showDuration / 2),
                quarterShowTime = Math.ceil(showDuration / 4);
            var onOldCaptionsHidden = $.createCountingCallback(toHideLength, function () {
                sliderRoot.dequeue("captions");
            });
            var onNewCaptionsShown = $.createCountingCallback(toShowLength, function () {
                sliderRoot.dequeue("captions");
            });

            function prepareTransition(done) {
                toHide.unsetTransition();
                toShow.unsetTransition().css(customSettings.captionsCssOff).show();
                $(oldWrapper).unsetTransition();
                $(newWrapper).unsetTransition().css(customSettings.wrapperCssOff).show();
                done();
            }

            function finalizeTransition(done) {
                $(oldWrapper).css(customSettings.wrapperCssOff);
                toHide.css(customSettings.captionsCssOff).hide();
                if ($.isFunction(cfg.callback)) {
                    cfg.callback();
                }
                done();
            }

            function hideOldCaptions() {
                if (toHideLength) {
                    toHide.each(function (i, c) {
                        $(c).setTransition(customSettings.captionsCssOff, quarterHideTime, easing, (quarterHideTime / toHideLength) * (queue ? i : 0), onOldCaptionsHidden);
                    });
                } else {
                    setTimeout(onOldCaptionsHidden, cfg.toHide.length ? quarterHideTime : 0);
                }
            }

            function hideOldCaptionsContainer(next) {
                if (oldWrapper) {
                    $(oldWrapper).setTransition(customSettings.wrapperCssOff, quarterHideTime, "linear", 0, next);
                } else {
                    setTimeout(next, cfg.toHide.length ? quarterHideTime : 0);
                }
            }

            function showNewCaptionsContainer(next) {
                if (newWrapper) {
                    $(newWrapper).setTransition(customSettings.wrapperCssOn, quarterShowTime, "linear", 0, next);
                } else {
                    setTimeout(next, quarterShowTime);
                }
            }

            function showNewCaptions() {
                if (toShowLength) {
                    toShow.each(function (i, c) {
                        $(c).setTransition(customSettings.captionsCssOn, quarterShowTime, easing, (quarterShowTime / toShowLength) * (queue ? i : 0), onNewCaptionsShown);
                    });
                } else {
                    setTimeout(onNewCaptionsShown, quarterShowTime);
                }
            }
            sliderRoot.queue("captions", []).queue("captions", prepareTransition).queue("captions", hideOldCaptions).queue("captions", hideOldCaptionsContainer).queue("captions", function (next) {
                setTimeout(next, delay);
            }).queue("captions", showNewCaptionsContainer).queue("captions", showNewCaptions).queue("captions", finalizeTransition).dequeue("captions");
        };
    };
    $.VamtamSlider.Effects.zoomIn = {
        init: function (slider) {
            if ($("html").is(".csstransitions.csstransforms")) {
                $(".slide-wrapper", slider.element).eq(0).wpvAddClass("current", slider.options.animationTime, slider.options.easing);
            } else {
                $.VamtamSlider.Effects.fade.init(slider);
            }
        },
        run: function (cfg) {
            if ($("html").is(".csstransitions.csstransforms")) {
                cfg.toShow.wpvAddClass("current", cfg.slider.options.animationTime, cfg.slider.options.easing, 0, cfg.callback);
                cfg.toHide.wpvRemoveClass("current", cfg.slider.options.animationTime, cfg.slider.options.easing);
            } else if (jQuery.WPV.Constants.vendor.transform) {
                cfg.toHide.stop(1, 0).css("zIndex", 1);
                cfg.toShow.css({
                    opacity: 0,
                    zIndex: 3
                }).show().stop(1, 0).css("dummy", 0).animate({
                    dummy: 1
                }, {
                    duration: cfg.slider.options.animationTime,
                    easing: "linear",
                    step: function (cur, fx) {
                        cfg.toShow.css("opacity", cur).css(jQuery.WPV.Constants.vendor.transform, "scale(" + cur + ")");
                        cfg.toHide.css("opacity", 1 - cur).css(jQuery.WPV.Constants.vendor.transform, "scale(" + (1 - cur) + ")");
                    },
                    complete: function () {
                        cfg.toShow.css("zIndex", 2);
                        cfg.toHide.hide();
                        cfg.callback();
                    }
                });
            } else {
                $.VamtamSlider.Effects.fade.run(cfg);
            }
        },
        changeCaptions: $.VamtamSlider.createCaptionEffect({
            captionsCssOff: {
                opacity: 0
            },
            captionsCssOn: {
                opacity: 1
            }
        })
    };
    $.VamtamSlider.Effects.slideAndFade = {
        init: function (slider) {
            var pos = slider.pos();
            $(".slide-wrapper", slider.element).each(function (i, o) {
                $(this).css({
                    opacity: i === pos ? 1 : 0,
                    display: i === pos ? "block" : "none"
                });
            });
        },
        run: function (cfg) {
            var shiftX = cfg.toShow.width() * cfg.direction;
            if ($(cfg.slider.element).is(".loaded")) {
                cfg.toShow.css("left", shiftX / 3);
            }
            cfg.toShow.stop(1, 0).css({
                zIndex: 2,
                opacity: 0,
                display: "block"
            });
            var done = 0;

            function cb() {
                if (++done == 2) cfg.callback();
            }
            if (cfg.toHide.length) {
                cfg.toHide.stop(1, 0).animate({
                    left: 0,
                    avoidTransforms: $.browser.mozilla
                }, cfg.duration, cfg.easing, function () {
                    $(this).css({
                        display: "none"
                    });
                    cb();
                }).animate({
                    opacity: 0
                }, {
                    duration: cfg.duration,
                    easing: "easeInCirc",
                    queue: false
                });
            } else {
                cb();
            }
            cfg.toShow.animate({
                left: 0,
                avoidTransforms: $.browser.mozilla
            }, {
                duration: cfg.duration,
                easing: cfg.easing,
                queue: false,
                complete: cb
            }).animate({
                opacity: 1
            }, {
                duration: cfg.duration,
                easing: "easeInCirc",
                queue: false
            });
        },
        changeCaptions: $.VamtamSlider.createCaptionEffect()
    };
    (function () {
        var thumbWidth = 150,
            thumbHeight = 100,
            thumbBorderBottom = 16,
            thumbBorderTop = 2,
            thumbInnerHeight = thumbHeight - thumbBorderBottom - thumbBorderTop,
            thumbPadding = 0,
            thumbSpace = 1,
            minThumbs = 2,
            maxThumbs = 6,
            left = 0;

        function getThumbnailsContainer(slider) {
            return $(slider.options.thumbNavContainer || slider.element).show();
        }     
        function getAvailableWidth(slider) {
            return getThumbnailsNavbar(slider).width();
        }

        function getNumberOfVisibleThumbs(slider) {
            var n = Math.floor((getAvailableWidth(slider) - 2) / (thumbWidth + thumbPadding * 2 + thumbSpace));
            n = Math.min(n, slider.slides.length);
            n = Math.min(n, maxThumbs);
            return n;
        }

        function getNavbarClientWidth(slider) {
            var len = getNumberOfVisibleThumbs(slider);
            return len * (thumbWidth + thumbPadding * 2) + Math.max(len - 1, 0) * thumbSpace;
        }

        function getNavbarScrollWidth(slider) {
            var len = slider.slides.length;
            return len * (thumbWidth + thumbPadding * 2) + Math.max(len - 1, 0) * thumbSpace;
        }

        function updateScroll(slider, newPos, oldPos, dir, callback) {
            var all = slider.totalSlides();
            var cnt = getNumberOfVisibleThumbs(slider);
            var step = thumbWidth + thumbPadding * 2 + thumbSpace;
            var halfVis = (cnt - 1) / 2;
            var visBefore = Math[dir == -1 ? "ceil" : "floor"](halfVis);
            var visAfter = Math[dir == -1 ? "floor" : "ceil"](halfVis);
            var pos = Math.max(newPos - visBefore, 0);
            var scroller = getThumbnailsScroller(slider);
            pos = Math.min(pos, all - cnt);
            scroller.setTransition({
                marginLeft: -pos * step
            }, 500, "swing", 0, function () {
                var active = $(".slider-thumb-wrapper", scroller).removeClass("active").eq(newPos);
                active.addClass("active");
                callback(active);
            });
        }

        function onResize(slider) {
            onResize = function (e, size) {
                var thumbMarker = getThumbnailsContainer(slider).find(".slider-thumb-marker");
                if (thumbMarker.length) {
                    thumb = thumbMarker.data("thumb");
                    if (thumb) {
                        thumbMarker.css({
                            left: thumb[0].offsetLeft
                        });
                    }
                }
                getThumbnailsNavbar(slider).css({
                    display: getNumberOfVisibleThumbs(slider) > 1 ? "block" : "none"
                });
            };
            return onResize;
        }

        function getThumbMarker(slider) {
            var d = $(slider.element).data("thumbMarker");
            return d || $();
        }
        var _tooltip;

        function getTooltip() {
            if (!_tooltip) {
                _tooltip = $('<div class="thumbnav-tooltip"/>').appendTo("body");
            }
            return _tooltip;
        }

        function showToltip(elem, text) {
            var tt = getTooltip().stop(1, 0).data("boundTo", elem[0]).html(text).css({
                top: elem.offset().top + elem.outerHeight() + 1,
                width: elem.outerWidth(),
                opacity: 0,
                display: "block",
                height: "auto"
            });
            var h = tt[0].scrollHeight;
            tt.css("height", 0).animate({
                opacity: 1,
                height: h,
                avoidCSSTransitions: true
            }, {
                queue: false,
                duration: 200
            });
            updateTooltipPosition()
        }

        function hideToltip() {
            if (_tooltip) {
                _tooltip.delay(300).stop(1, 0).removeData("boundTo").animate({
                    opacity: 0,
                    height: 0,
                    avoidCSSTransitions: true
                });
            }
        }
        var _lastTTx = 0;

        function updateTooltipPosition(noAnim) {
            var tt = getTooltip(),
                el = tt.data("boundTo");
            if (tt && el) {
                var x = $(el).offset().left;
                if (x !== _lastTTx) {
                    _lastTTx = x;
                    tt.css({
                        left: x,
                        height: "auto"
                    });
                }
            }
        }
        $.VamtamSlider.Effects.thumbNav = {
            init: function (slider) {
                $.VamtamSlider.Effects.slideAndFade.init(slider);
                var btnWrap = $('<div class="slider-nav-buttons-wrap" />').appendTo(slider.element);
                var div = $('<div class="slider-nav-buttons" />').appendTo(btnWrap);
                var btnPrev = $('<div class="slider-nav-btn prev" />').appendTo(div).mousedown(function () {
                    slider.pos("prev");
                    return false;
                });
                var btnCnt = $('<div class="slider-nav-btn cnt" />').appendTo(div);
                var btnNext = $('<div class="slider-nav-btn next" />').appendTo(div).mousedown(function () {
                    slider.pos("next");
                    return false;
                });
                var curPos = slider.pos(),
                    scroller = getThumbnailsScroller(slider);
                $.each(slider.slides, function (i, slide) {
                    var thumb = $('<div class="slider-thumb-wrapper"/>');
                    var classNames = ["bg-thumbnail", slide.type];
                    if (!slide.thumbUrl && !slide.url) {
                        classNames.push("no-image");
                    }
                    thumb.thumbnail({
                        classNames: classNames.join(" "),
                        url: slide.thumbUrl || slide.url,
                        resizing: slide.thumbUrl ? "contain" : "cover"
                    }).click(function () {
                        slider.pos(i);
                    });
                    thumb.find(".bg-thumbnail").hover(function () {
                        if (!$.WPV.Constants.vendor.transition) $(this).originalStop(1, 0).originalAnimate({
                            marginTop: 0
                        }, 500, "swing");
                        if (slide.shortText) showToltip(thumb, slide.shortText);
                    }, function () {
                        if (!$.WPV.Constants.vendor.transition) $(this).originalStop(1, 0).originalAnimate({
                            marginTop: thumbHeight - thumbBorderBottom
                        }, 500, "swing");
                        hideToltip();
                    });
                    thumb.appendTo(scroller);
                });
                var thumbMarker = $('<div class="slider-thumb-marker" />').hover(function () {
                    scroller.find(".slider-thumb-wrapper.active").trigger("mouseenter");
                }, function () {
                    scroller.find(".slider-thumb-wrapper.active").trigger("mouseleave");
                }).appendTo(scroller);
                $(slider.options.thumbNavContainer || slider.element).data("slider", slider).watchResize(onResize(slider)).triggerHandler("elementResize");
                $(slider.element).bind("slidePositionChange.thumbNav", function (e, newPos, oldPos, dir) {
                    btnCnt.html((newPos + 1) + "/" + slider.slides.length);
                    getThumbnailsNavbar(slider).css("right", $(slider.element).find(".slider-nav-buttons").outerWidth() + 20);
                    updateScroll(slider, newPos, oldPos, dir, function (thumb) {
                        thumbMarker.data("thumb", thumb).css("left", thumb[0].offsetLeft);
                    });
                });
            },
            uninit: function (slider) {
                $(slider.element).unbind(".thumbNav");
                $(slider.options.thumbNavContainer || slider.element).unwatchResize(onResize);
                getThumbnailsNavbar(slider).remove();
                $(".slider-nav-buttons", slider.element).remove();
                getThumbMarker(slider).remove();
                _tooltip = null;
                getTooltip().remove();
            },
            run: $.VamtamSlider.Effects.slideAndFade.run,
            changeCaptions: $.VamtamSlider.Effects.slideAndFade.changeCaptions
        };
    })();

    function isComplexSlideWrapper(wrapper) {
        return $(wrapper).find(".transition").length > 0;
    }
    (function () {
        var transitionCss = {}, mainTimer = 0,
            captionsTimer = 0,
            useTransitions = !! $.WPV.Constants.vendor.transition,
            useTransforms = !! $.WPV.Constants.vendor.transform,
            supports3d = !! $.getCssPropertyName("transform-style"),
            preferTranslate = useTransitions && useTransforms,
            prefer3d = supports3d && !$.browser.mozilla;
        var animateable = {
            top: 1,
            right: 1,
            bottom: 1,
            left: 1,
            "margin-top": 1,
            "margin-right": 1,
            "margin-bottom": 1,
            "margin-left": 1,
            "padding-top": 1,
            "padding-right": 1,
            "padding-bottom": 1,
            "padding-left": 1,
            zoom: 1,
            opacity: 1,
            width: 1,
            height: 1,
            "font-size": 1
        };

        function parseCss(css) {
            var style = {}, pairs = $.trim(String(css)).split(";"),
                len = pairs.length,
                pair, name, value;
            for (var i = 0; i < len; i++) {
                pair = $.trim(pairs[i]);
                if (!pair) continue;
                pair = pair.split(":");
                name = $.trim(pair[0]).toLowerCase();
                if (!(name in animateable)) continue;
                name = $.getCssPropertyName(name) || name;
                value = $.trim(pair[1]);
                if (name) {
                    if (name == "opacity") {
                        value = parseFloat(value);
                        if (isNaN(value)) {
                            continue;
                        }
                    }
                    style[name] = value;
                }
            }
            return style;
        }

        function translateCss(style, setZeros) {
            if (preferTranslate) {
                var map = {
                    "bottom": {
                        axis: "y",
                        q: -1
                    },
                    "top": {
                        axis: "y",
                        q: 1
                    },
                    "left": {
                        axis: "x",
                        q: 1
                    },
                    "right": {
                        axis: "x",
                        q: -1
                    }
                };
                var t = {
                    x: null,
                    y: null
                };
                $.each(map, function (name, data) {
                    if (name in style) {
                        if (setZeros) {
                            t[data.axis] = 0;
                        } else {
                            var m = style[name].match(/\s*(-?\d+(\.d+)?)(.*)?\s*/),
                                value = 0,
                                unit = "px";
                            if (m) {
                                if (m[1]) value = parseFloat(m[1]);
                                if (m[3]) unit = m[3];
                            }
                            t[data.axis] = data.q === 1 ? value + "" + unit : (value * data.q) + "" + unit;
                        }
                    }
                });
                if (t.x !== null || t.y !== null) {
                    if (prefer3d) {
                        style[$.WPV.Constants.vendor.transform] = "translate3d(" + (t.x || 0) + ", " + (t.y || 0) + ", 0)";
                    } else {
                        style[$.WPV.Constants.vendor.transform] = "translate(" + (t.x || 0) + ", " + (t.y || 0) + ")";
                    }
                }
            }
            return style;
        }

        function getTransitionDuration(elem, slider) {
            var $elem = $(elem);
            if (!$elem.length) return 0;
            return parseFloat($.trim($elem.attr("duration")) || slider.option("animationTime") || 1000);
        }

        function getTransitionDelay(elem, slider) {
            return parseFloat($.trim(elem.getAttribute("delay")) || 0);
        }

        function getTransitionEasing(elem, slider) {
            var easing = $.trim(elem.getAttribute("easing") || slider.option("easing"));
            if (!easing || !(easing in $.WPV.Constants.Esing)) easing = "swing";
            return easing;
        }

        function prepareTransition(elem, slider) {
            var cssFrom = elem.getAttribute("cssfrom");
            var cssTo = elem.getAttribute("cssto") || elem.getAttribute("style");
            if (cssFrom && cssTo) {
                cssFrom = parseCss(cssFrom);
                cssTo = parseCss(cssTo);
                cssFrom = translateCss(cssFrom);
                cssTo = translateCss(cssTo, true);
                $(elem).css(cssFrom);
                $(elem).data("cssFrom", $.isEmptyObject(cssFrom) ? null : cssFrom);
                $(elem).data("cssTo", $.isEmptyObject(cssTo) ? null : cssTo);
            }
        }

        function prepareSlide(slideWrapper, slider, multiplier) {
            var slideDuration = getTransitionDuration(slideWrapper[0], slider) / 2;
            var aniated = slideWrapper.find(".transition");
            var q = 1;
            if (slider.options.forceNestedAnimationTimes) {
                var maxTime = 0;
                aniated.each(function (j, o) {
                    maxTime = Math.max(maxTime, getTransitionDuration(o, slider) + getTransitionDelay(o, slider));
                });
                q = slideDuration / maxTime;
                if (multiplier !== undefined) q *= multiplier;
            }
            aniated.each(function (j, o) {
                o.setAttribute("duration", Math.ceil(getTransitionDuration(o, slider) * q));
                o.setAttribute("delay", Math.ceil(getTransitionDelay(o, slider) * q));
                prepareTransition(o, slider);
            });
            prepareTransition(slideWrapper[0], slider);
        }

        function runTransition(elem, type, slider, callback, overrideSettings) {
            var cssFrom = $(elem).data(type == "hide" ? "cssFrom" : "cssTo");
            if (cssFrom) {
                var cfg = $.extend({
                    duration: getTransitionDuration(elem, slider),
                    easing: getTransitionEasing(elem, slider),
                    delay: getTransitionDelay(elem, slider)
                }, overrideSettings);
                $(elem).setTransition(cssFrom, cfg.duration, cfg.easing, cfg.delay, callback || $.noop);
            } else {
                (callback || $.noop).call(elem);
            }
        }

        function getThumbnailsNavbar(slider) {
            var bar = $("#header-slider-thumbs");
            if (!bar.length) {
                bar = $('<div id="header-slider-thumbs"/>').appendTo("#sub-header");
                bar.html('<div class="limit-wrapper">\
                    <div class="header-slider-thumbs-prev icon"></div>\
                        <div class="header-slider-thumbs-scroller">\
                            <div class="header-slider-thumbs-container"></div>\
                            <div class="counter-container"></div>\
                        </div>\
                        <div class="header-slider-thumbs-next icon"></div>\
                    </div>');
                var CONTAINER = bar.find(".header-slider-thumbs-container");
                var COUNTER_WIDTH = 22;
                var COUNTER_PAD_X = 20;
                var WIDTH_MAX = 960;
                var WIDTH_MIN = 200;
                var THUMB_OUTER_WIDTH = 99;
                var COUNTER_SPACE = 92;
                var len = slider.slides.length,
                    mid = Math.ceil(len / 2),
                    thumb, slide;
                for (var i = 0; i < slider.slides.length; i++) {
                    slide = slider.slides[i];
                    thumb = $('<div class="thumbnail"/>').click((function (pos) {
                        return function () {
                            slider.pos(pos);
                        };
                    })(i)).appendTo(CONTAINER);
                    var classNames = ["bg-thumbnail", slide.type];
                    if (!slide.thumbUrl && !slide.url) {
                        classNames.push("no-image");
                    }
                    if (slide.thumbUrl || slide.url) {
                        thumb.thumbnail({
                            classNames: classNames.join(" "),
                            url: slide.thumbUrl || slide.url,
                            resizing: slide.thumbUrl ? "contain" : "cover"
                        });
                    } else {
                        thumb.html('<div>' + (i + 1) + '</div>');
                    }
                    if (slide.shortText) {
                        thumb.attr("title", slide.shortText);
                    }
                }

                function reflowThumbnails(pos) {
                    var thumbs = bar.find(".thumbnail");
                    var thumbsLen = thumbs.length;
                    if (!thumbsLen) return;
                    var isFullWidth = bar.find(".limit-wrapper").width() >= 960;
                    var container = bar.find(".header-slider-thumbs-container");
                    var maxThumbs = isFullWidth ? 7 : Math.floor((container.width() - THUMB_OUTER_WIDTH) / THUMB_OUTER_WIDTH);
                    var newPos = pos === undefined ? slider.pos() : pos;
                    var firstVisible = Math.max(newPos - maxThumbs, 0);
                    bar.find(".counter-container").css("left", isFullWidth ? "50%" : "-9999%");
                    thumbs.filter(":last").css("marginRight", 0);
                    if (thumbsLen <= maxThumbs && isFullWidth) {
                        if (isFullWidth && thumbsLen === 1) {
                            thumbs.css("marginLeft", -THUMB_OUTER_WIDTH - COUNTER_SPACE);
                        } else {
                            if (isFullWidth) {
                                var cnt1 = Math.ceil(thumbsLen / 2);
                                var cnt2 = thumbsLen - cnt1;
                                thumbs.each(function (i, o) {
                                    var left = 0;
                                    if (cnt1 === cnt2) {
                                        if (cnt2 === i) {
                                            left = COUNTER_SPACE;
                                        }
                                    } else {
                                        if (i == cnt2 + 1) left = COUNTER_SPACE;
                                        if (i === 0) left = -THUMB_OUTER_WIDTH;
                                    }
                                   
                                    if($.browser.msie && $.browser.version < 10)
                                    {
                                
                                    $(o).setTransition({
                                        marginLeft: left
                                        
                                        
                                    }, 500, "easeInOutQuad", 200);
                                    }
                                    else
                                    {
                                        $(o).setTransition({
                                        marginRight: left
                                    }, 500, "easeInOutQuad", 200);
                                    }
                                });
                            }
                        }
                        return;
                    }
                    thumbs.each(function (i, o) {
                        $thumb = $(o);
                        var left = 0;
                        if (i === 0) {
                            if (!isFullWidth && newPos === thumbsLen - 1) {
                                left = newPos <= maxThumbs ? 0 : container.parent().width() - thumbsLen * THUMB_OUTER_WIDTH;
                            } else {
                                left = firstVisible > 0 ? -THUMB_OUTER_WIDTH * (newPos - maxThumbs) : 0;
                            }
                        } else if (isFullWidth && i == firstVisible + 4) {
                            left = COUNTER_SPACE;
                        }
                        $thumb.setTransition({
                            marginLeft: left
                        }, 500, "easeInOutQuad", 200);
                    });
                }
                $(window).bind("resize.thumbnailsbar", function () {
                    reflowThumbnails();
                });
                $('#header-slider').bind("slidePositionChange.counter", function (e, newPos, oldPos, dir) {
                    bar.find(".counter-container").counter(newPos + 1, bar.find(".limit-wrapper").width() < 960);
                    reflowThumbnails(newPos);
                });
                bar.find(".header-slider-thumbs-prev").click(function () {
                    $('#header-slider').vamtamSlider("pos", "prev");
                    return false;
                });
                bar.find(".header-slider-thumbs-next").click(function () {
                    $('#header-slider').vamtamSlider("pos", "next");
                    return false;
                });
            }
            return bar;
        }
        $.VamtamSlider.Effects.Sintia = $.VamtamSlider.Effects.sintia = {
            init: function (slider) {
                var pos = Math.max(slider.pos(), 0);
                $(".slide-wrapper", slider.element).each(function (i, o) {
                    $(this).attr({
                        cssfrom: "opacity: 0;",
                        cssto: "opacity: 1;",
                        easing: slider.options.easing,
                        duration: slider.options[isComplexSlideWrapper(o) ? "complexSlidesDuration" : "animationTime"]
                    }).addClass("transition").css({
                        opacity: i === pos ? 1 : 0,
                        display: i === pos ? "block" : "none"
                    });
                    prepareSlide($(this), slider);
                });
                getThumbnailsNavbar(slider);
                $(function () {
                    var thumbs = $("#header-slider-thumbs .thumbnail");
                    var last = thumbs.eq(thumbs.length - 1);
                    var wasActive = last.is(".active");
                    last.addClass("active");
                    var defaultBgColor = last.css("backgroundColor");
                    if (!wasActive) {
                        last.removeClass("active");
                    }
                    $("#header-slider").bind("slidePositionChange", function (e, newIndex) {
                        var color = defaultBgColor;
                        var bg = $(this).find(".slide-wrapper:eq(" + newIndex + ") .slide .slide-bg");
                        if (bg.length) {
                            color = bg.css("backgroundColor");
                            if (!color || color == "transparent") {
                                color = defaultBgColor;
                            }
                            if (color.indexOf("rgb(") == 0 && !($.browser.msie && $.browser.version < 9)) {
                                color = color.replace(")", ", 0.5)").replace("rgb(", "rgba(");
                            }
                        }
                        $("#header-slider-thumbs .thumbnail").removeClass("active").css("background-color", "transparent").eq(newIndex).addClass("active").css("background-color", color);
                    });
                });
            },
            uninit: function (slider) {
                $(slider.element).unbind("slidePositionChange.counter");
                $("#header-slider-thumbs").find(".header-slider-thumbs-prev a").unbind().end().find(".header-slider-thumbs-next a").unbind().end().off("click", ".thumbnail").empty().remove();
            },
            run: function (cfg) {
                if (cfg.toHide[0] === cfg.toShow[0]) {
                    cfg.callback();
                    return;
                }
                cfg.toHide.unsetTransition().find(".transition").unsetTransition(1, 1);
                cfg.toShow.unsetTransition().find(".transition").unsetTransition(1, 1);
                cfg.toHide.css({
                    "zIndex": 1
                }).find(".table").toFixedWidth();
                cfg.toShow.css({
                    "zIndex": 2
                }).find(".table").css("width", "100%");
                var expectedAnimationsCount = 0;
                if (cfg.toHide.length) {
                    expectedAnimationsCount += cfg.toShow.length;
                    expectedAnimationsCount += cfg.toShow.find(".transition").length;
                    expectedAnimationsCount += cfg.toHide.length;
                    expectedAnimationsCount += cfg.toHide.find(".transition").length;
                }
                var showTimer;
                var cb = expectedAnimationsCount ? $.createCountingCallback(expectedAnimationsCount, function () {
                    if (showTimer) clearTimeout(showTimer);
                    cfg.toHide.find(".table").css("width", "100%");
                    cfg.toHide.css("display", "none");
                    cfg.callback();
                }) : $.noop;
                var elementsToHide = cfg.toHide.find(".transition");
                var elementsToShow = cfg.toShow.find(".transition");
                var elementsToHideLen = elementsToHide.length;
                var elementsToShowLen = elementsToShow.length;
                var showDelay = 0,
                    showDuration = getTransitionDuration(cfg.toShow, cfg.slider),
                    hideDuration = getTransitionDuration(cfg.toHide, cfg.slider);
                if (elementsToHideLen > 0 && elementsToShowLen === 0) {
                    showDelay = hideDuration / 2;
                } else if (elementsToHideLen === 0 && elementsToShowLen > 0) {
                    showDelay = hideDuration / 2;
                    hideDuration = hideDuration / 2;
                }
                cfg.toShow.css("display", "block").each(function (i, o) {
                    runTransition(o, "show", cfg.slider, cb, {
                        delay: showDelay,
                        duration: cfg.duration
                    });
                });
                cfg.toHide.each(function (i, o) {
                    runTransition(o, "hide", cfg.slider, cb, {
                        duration: hideDuration
                    });
                });

                function showSub() {
                    if (showTimer) clearTimeout(showTimer);
                    showTimer = setTimeout(function () {
                        elementsToShow.each(function (i, o) {
                            runTransition(o, "show", cfg.slider, cb);
                        });
                    }, showDelay);
                }
                if (elementsToHide.length) {
                    var cb2 = $.createCountingCallback(elementsToHide.length, function () {
                        showSub();
                    });
                    elementsToHide.each(function (i, o1) {
                        if ($(o1).is(".slide-bg")) {
                            cb();
                            cb2();
                        }
                        runTransition(o1, "hide", cfg.slider, function () {
                            if (!$(o1).is(".slide-bg")) {
                                cb();
                                cb2();
                            }
                        });
                    });
                } else {
                    showSub();
                }
                if (!expectedAnimationsCount) {
                    cfg.callback();
                }
            },
            changeCaptions: function (cfg) {
                var oldWrapper = cfg.toHide.data("captionsWarapper"),
                    newWrapper = cfg.toShow.data("captionsWarapper"),
                    toHide = $(oldWrapper).find(".caption"),
                    toShow = $(newWrapper).find(".caption"),
                    toHideLength = toHide.length,
                    toShowLength = toShow.length,
                    duration = cfg.duration || 1000;
                $.VamtamSlider.Effects.slideAndFade.changeCaptions($.extend({}, cfg, {
                    captionFxDelay: toHideLength && toShowLength ? 0 : Math.ceil(duration * .75),
                    captionFxTime: Math.ceil(duration / 2)
                }));
            }
        };
    })();
    $(function () {
        var headerBgImage, sliderBgImage;
        $("#header-slider").bind({
            beforeExpand: function () {
                headerBgImage = $(".fixed-header-box").css("backgroundImage");
                sliderBgImage = $(".header-slider-wrapper").css("backgroundImage");
                if (headerBgImage) $(".fixed-header-box").css("backgroundImage", "none");
                if (sliderBgImage) $(".header-slider-wrapper").css("backgroundImage", "none");
            },
            afterExpand: function () {
                if (headerBgImage) $(".fixed-header-box").css("backgroundImage", headerBgImage);
                if (sliderBgImage) $(".header-slider-wrapper").css("backgroundImage", sliderBgImage);
            }
        });
    });
    $.VamtamSlider.Effects.slide.changeCaptions = $.VamtamSlider.createCaptionEffect({
        captionsCssOff: {
            opacity: 0
        },
        captionsCssOn: {
            opacity: 1
        }
    });
    $.VamtamSlider.Effects.fade.changeCaptions = $.VamtamSlider.createCaptionEffect({
        captionsCssOff: {
            opacity: 0
        },
        captionsCssOn: {
            opacity: 1
        }
    });
})(jQuery);